<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>智慧社区后台</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/plugins/bootstrap-table/css/bootstrap-table.css">
</head>
<style>
</style>
<body style="padding-bottom: 90px; background-color: #ECF0F5;">
	<section class="content" style="margin: 15px; background-color: white;">
		<div class="row">
			<div class="col-sm-12">
				<table id="table">
					<thead style="background-color: #00C0EF">
						<tr style="background-color: #00C0EF">
							<!-- 							<th class="text-center col-sm-1" data-field=""></th> -->
							<th class="text-center col-sm-2" data-field="userName">姓名</th>
							<th class="text-center col-sm-2" data-field="userMobile">电话</th>
							<th class="text-center col-sm-2" data-field="invitationCodeI">身份</th>
							<th class="text-center col-sm-2" data-field="communityName">任岗情况</th>
							<th class="text-center col-sm-1" data-field="userStatus">状态</th>
							<th class="text-center col-sm-1" data-field="id">操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</section>
	<!-- Large modal -->
	<div id="modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">App用户信息</h4>
				</div>
				<div class="modal-body">
					<div class="input-group">
						<span class="input-group-addon">姓名:</span> <input type="text" class="form-control" id="userName" readonly>
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">身份证:</span> <input type="text" class="form-control" id="userIdcard" readonly>
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">电话:</span> <input type="text" class="form-control" id="userMobile" readonly>
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">身份信息:</span> <input type="text" class="form-control" id="userIndentity" readonly>
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">就业状态:</span> <input type="text" class="form-control" id="conpeople" readonly>
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">政治面貌:</span> <input type="text" class="form-control" id="deposit" readonly>
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">任岗情况:</span> <input type="text" class="form-control" id="communityName" readonly>
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">车牌号:</span> <input type="text" class="form-control" id="userIntegral" readonly>
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">楼栋:</span> <input type="text" class="form-control" id="userAddress" readonly>
					</div>
					<br>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-export.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/tableExport.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-toolbar.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-filter-control.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>


<script>
	function actionFormatter(value, row, index) {
		var del = "";
		if (row.userStatus == 1) {
			del = "<button class='btn btn-warning btn-xs glyphicon glyphicon-trash' onclick='ds_delete(this,\"" + row.userId + "\");'>冻结</button>";
		} else {
			del = "<button class='btn btn-info btn-xs glyphicon glyphicon-trash' onclick='ds_thaw(this,\"" + row.userId + "\");'>解结</button>";
		}
		return [ "<button class='btn btn-primary btn-xs glyphicon glyphicon-pencil' onclick='showModal(\"" + row.userId + "\");'>查看</button>",
				"&nbsp;" + del + "&nbsp;<button class='btn btn-success btn-xs glyphicon glyphicon-repeat' onclick='resetPass(\"" + row.userId + "\")'>重置密码</button>", ].join('');
	}
	var table_dataset = [
	// 		{
	// 		field : 'id',
	// 		checkbox : true,
	// 	}, 
	{
		field : 'userName',
		align : 'center',
	}, {
		field : 'userMobile',
		align : 'center',
	}, {
		field : 'userIndentity',
		align : 'center',
	}, {
		field : 'communityName',
		align : 'center',
	// 		formatter : function nameFormatter(value, row, index) {
	// 			var str = "";
	// 			var communityName = row.communityName + '';
	// 			if (row.communityName != null & communityName != '') {
	// 				str = communityName.substring(1);
	// 			} else {
	// 				str = "-";
	// 			}
	// 			return str;
	// 		}
	}, {
		field : 'userStatus',
		align : 'center',
		formatter : function userStatusFormatter(value, row, index) {
			var str = "";
			if (row.userStatus == 1) {
				str = "正常";
			} else {
				str = "冻结";
			}
			return str;
		},
	}, {
		align : 'center',
		width : 150,
		formatter : actionFormatter,
	} ];
	$('#table').bootstrapTable(
			{
				url : "${pageContext.request.contextPath}/selectAppUser",
				idField : "id",
				columns : table_dataset,
				striped : true, //是否显示行间隔色
				pagination : true, //是否显示分页
				pageSize : 10, //每页的记录行数
				pageList : [ 10, 25, 50, 100 ], //可供选择的每页的行数
				search : false,
				showRefresh : true,
				sidePagination : "server", //表示服务端请求  
				queryParamsType : "limit",
				queryParams : function queryParams(params) { //设置查询参数  
					var param = {
						offset : params.offset,
						limit : params.limit,
						kod : $("#kod").val()
					};
					return param;
				},
				// 				"<div style='float:left;'><button class='btn btn-warning glyphicon glyphicon-trash' onclick='delChecked();'>批量冻结</button></div>"
				toolbar : "<div class='input-group' style='width:250px;float:right;margin-top:2px;'><input type='text' class='form-control' id='kod' name='kod'>" + ''
						+ "<span class='input-group-btn'><button class='btn btn-default' type='button' onclick='selectQuerry();'>查询</button></span></div>",

				icons : {
					paginationSwitchDown : 'glyphicon-collapse-down icon-chevron-down',
					paginationSwitchUp : 'glyphicon-collapse-up icon-chevron-up',
					refresh : 'glyphicon-refresh icon-refresh',
					toggle : 'glyphicon-list-alt icon-list-alt',
					columns : 'glyphicon-th icon-th',
					detailOpen : 'glyphicon-plus icon-plus',
					detailClose : 'glyphicon-minus icon-minus',
					"export" : 'glyphicon-export icon-share'
				},
				showExport : true,
				exportDataType : 'basic',
				exportTypes : [ 'json', 'xml', 'csv', 'txt', 'sql', 'excel' ]
			});

	function showModal(id) {
		$.ajax({
			url : "${pageContext.request.contextPath}/selectAppUserById",
			type : "post",
			data : {
				userId : id
			},
			dataType : "json",
			success : function(map) {
				var data = map['appUser'];
				$("#userName").val(data.userName);
				$("#userMobile").val(data.userMobile);
				$("#conpeople").val(data.conpeople);
				$("#deposit").val(data.deposit);
				$("#communityName").val(data.communityName);
				$("#userIntegral").val(data.userIntegral);
				$("#userAddress").val(data.userAddress);
				$("#userIndentity").val(data.userIndentity);
				$("#userIdcard").val(data.userIdCard);
				$('#modal').modal({
					backdrop : 'static',
					keyboard : false
				});
			},
			error : function() {
				layer.msg('系统异常!', {
					icon : 2,
					time : 800
				});
			}
		});
	}

	function ds_delete(obj, userId) {
		layer.confirm('确认要冻结吗？', function(index) {
			$.ajax({
				url : "${pageContext.request.contextPath}/deleteAppUserByIds",
				type : "post",
				data : {
					"id" : userId
				},
				dataType : "json",
				success : function(data) {
					if (data.result === 1) {
						layer.msg('已冻结!', {
							icon : 1,
							time : 1000
						});
						$("#table").bootstrapTable('refresh');
					} else {
						layer.msg('冻结失败!', {
							icon : 5,
							time : 800
						});
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
				}
			});

		});
	}

	function ds_thaw(obj, userId) {
		layer.confirm('确认要解冻吗？', function(index) {
			$.ajax({
				url : "${pageContext.request.contextPath}/thawAppUserByIds",
				type : "post",
				data : {
					"id" : userId
				},
				dataType : "json",
				success : function(data) {
					if (data.result === 1) {
						layer.msg('已解冻!', {
							icon : 1,
							time : 1000
						});
						$("#table").bootstrapTable('refresh');
					} else {
						layer.msg('解冻失败!', {
							icon : 5,
							time : 800
						});
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
				}
			});

		});
	}

	function selectQuerry() {
		$("#table").bootstrapTable('refresh');
	}

	//批量删除
	function delChecked() {
		var ids = "";
		var rows = $("#table").bootstrapTable('getSelections');
		if (rows.length == 0) {
			layer.msg('请先选择要冻结的项!', {
				icon : 3,
				time : 1000
			});
			return;
		}
		for (var i = 0; i < rows.length; i++) {
			if (i == 0) {
				ids = rows[i].userId;
			} else {
				ids += "," + rows[i].userId;
			}
		}
		layer.confirm('确认要冻结吗？', function(index) {
			$.ajax({
				url : "${pageContext.request.contextPath}/deleteAppUserByIds",
				type : "post",
				data : {
					"id" : ids
				},
				dataType : "json",
				success : function(data) {
					if (data.result === 1) {
						layer.msg('已冻结!', {
							icon : 1,
							time : 1000
						});
						$("#table").bootstrapTable('refresh');
					} else {
						layer.msg('冻结失败!', {
							icon : 5,
							time : 800
						});
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
				}
			});
		});
	}

	function resetPass(id) {
		layer.confirm("是否要重置密码为123456？", function(index) {
			$.ajax({
				url : "${pageContext.request.contextPath}/appUserUpdate",
				type : "post",
				data : {
					userId : id,
					userPassword : '123456'
				},
				dataType : "json",
				success : function(data) {
					if (data.result == 1) {
						layer.msg('操作成功!', {
							icon : 1,
							time : 800
						});
					} else {
						layer.msg('操作失败!', {
							icon : 2,
							time : 800
						});
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
				}
			});
		});
	}
</script>
</html>
